package mortal.game.control
{
    import Framework.MQ.*;
    import Message.BroadCast.*;
    import Message.Command.*;
    import Message.Db.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.debug.*;
    import com.gengine.game.core.*;
    import com.gengine.keyBoard.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.component.gconst.*;
    import mortal.game.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.rules.*;
    import mortal.game.scene.*;
    import mortal.game.scene.ai.*;
    import mortal.game.scene.events.*;
    import mortal.game.scene.layer.utils.*;
    import mortal.game.scene.map.*;
    import mortal.game.scene.mount.*;
    import mortal.game.scene.player.*;
    import mortal.game.scene.player.entity.*;
    import mortal.game.scene.skill.*;
    import mortal.game.view.system.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class SceneController extends Controller
    {
        private var _scene:GameScene;
        private var _entritysAry:Array;
        private var _dropItemAry:Array;
        private var _npcShopAry:Array;
        private var _prePoint:Point;
        private var _taskTargt:TaskTargetInfo;

        public function SceneController()
        {
            this._entritysAry = [];
            this._dropItemAry = [];
            this._npcShopAry = [];
            
        }

        override protected function initView() : IView
        {
            this._scene = Game.scene;
            if (this._scene != null)
            {
                this._scene.addEventListener(SceneEvent.INIT, this.onSceneInitHandler);
                Dispatcher.addEventListener(EventName.Player_Selected, this.onPlayerSelectedHandler, false, 9999);
            }
            return this._scene;
        }

        private function onPlayerSelectedHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as IEntity;
            if (_loc_2 && _loc_2.selected)
            {
                if (ThingUtil.selectEntity)
                {
                    ThingUtil.selectEntity.selected = false;
                }
                ThingUtil.selectEntity = _loc_2;
            }
            else
            {
                ThingUtil.selectEntity = null;
            }
            
        }

        private function onNpcSelectedHandler(event:DataEvent) : void
        {
            Dispatcher.dispatchEvent(event);
            
        }

        private function onSceneInitHandler(event:SceneEvent) : void
        {
            Log.debug("SceneInit:");
            if (this._entritysAry.length)
            {
                Log.debug("_entritysAry:" + this._entritysAry);
                this.addEntitys(this._entritysAry);
                this._entritysAry.length = 0;
            }
            while (this._dropItemAry.length > 0)
            {
                
                ThingUtil.dropItemUtil.addDropItem(this._dropItemAry.shift() as SPacket);
            }
            this._dropItemAry.length = 0;
            while (this._npcShopAry.length > 0)
            {
                
                ThingUtil.npcShopUtil.addNpcShop(this._npcShopAry.shift() as SNpcShop);
            }
            this._npcShopAry.length = 0;
            AIManager.init(this._scene, RolePlayer.instance);
            RolePlayer.instance.addEventListener(PlayerEvent.UPDATEINFO, this.onEntityInfoUpdateHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.GIRD_WALK_START, this.onGirdWalkStartHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.ServerPoint, this.onGirdWalkStartHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.WALK_END, this.onWalkEndHandler);
            Dispatcher.dispatchEvent(new DataEvent(EventName.MapUpdateRolePosition, RolePlayer.instance.currentPoint));
            this._scene.addEventListener(MouseEvent.CLICK, this.onSceneClickHandler);
            if (Cache.instance.role.entityInfo.life <= 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Role_Dead));
            }
            MapDataUpdater.updateMapDataBySharp();
            ThingUtil.isEntitySort = true;
            ThingUtil.isMoveChange = true;
            this._scene.playerLayer.sortEntitys();
            this.onUpdateNPCStatus(cache.scene.allNpcStatusUpdate());
            AIManager.cancelAll();
            cache.scene.sceneChange();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Scene_Update, Game.sceneInfo));
            
        }

        private function onGirdWalkStartHandler(event:PlayerEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MapUpdateRolePosition, RolePlayer.instance.currentPoint));
            if (RolePlayer.instance.isCanControlWalk)
            {
                GameProxy.sceneProxy.move(RolePlayer.instance.serverPoints);
            }
            
        }

        private function onWalkEndHandler(event:PlayerEvent) : void
        {
            this._scene.removePointMark();
            Dispatcher.dispatchEvent(new DataEvent(EventName.RoleMoveEnd, RolePlayer.instance.currentPoint));
            
        }

        private function onSceneClickHandler(event:MouseEvent) : void
        {
            var _loc_3:UserPlayer = null;
            var _loc_4:UserPlayer = null;
            if (RolePlayer.instance.isTweening)
            {
                
            }
            var _loc_2:* = ThingUtil.onClickScene();
            if (RolePlayer.instance.entityInfo.isStall)
            {
                _loc_3 = _loc_2 as UserPlayer;
                if (_loc_3 && _loc_3.entityInfo.isStall)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.StallOpenStall, _loc_3.entityInfo.entityInfo.entityId));
                }
                else
                {
                    MsgManager.addBroadCast("摆摊中……");
                }
                
            }
            else if (_loc_2 is UserPlayer)
            {
                _loc_4 = _loc_2 as UserPlayer;
                if (_loc_4 && _loc_4.entityInfo.isStall)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.StallOpenStall, _loc_4.entityInfo.entityInfo.entityId));
                    
                }
            }
            this.sceneClickEntity(_loc_2, event);
            
        }

        private function sceneClickEntity(param1:GameSprite, param2:MouseEvent) : void
        {
            var _loc_3:IEntity = null;
            var _loc_4:Point = null;
            if (param1 && param1 is RolePlayer == false)
            {
                this._scene.removePointMark();
                if (param1 is IEntity)
                {
                    _loc_3 = param1 as IEntity;
                    if (!RolePlayer.instance.isCanControlWalk)
                    {
                        _loc_3.selected = true;
                        
                    }
                    if (KeyBoardManager.getKeyData(KeyCode.SHIFT).isKeyDown)
                    {
                        _loc_3.selected = true;
                        
                    }
                    if (ThingUtil.entityUtil.isAttackAble(_loc_3) && !SystemSetter.currentSetter.clickToFight)
                    {
                        if (_loc_3.selected)
                        {
                            AIManager.onAIControl(param1, AIType.AI_Entity);
                        }
                        else
                        {
                            _loc_3.selected = true;
                        }
                    }
                    else
                    {
                        _loc_3.selected = true;
                        AIManager.onAIControl(param1, AIType.AI_Entity);
                    }
                }
                else
                {
                    if (!RolePlayer.instance.isCanControlWalk)
                    {
                        
                    }
                    AIManager.onAIControl(param1, AIType.AI_Scene);
                }
            }
            else
            {
                if (AIManager.isStopWalk || !RolePlayer.instance.isCanControlWalk)
                {
                    
                }
                GameController.guide.breakAutoPath();
                this._scene.addPointMark(param2.localX, param2.localY);
                _loc_4 = GameMapUtil.getTilePoint(param2.localX, param2.localY);
                if (this._prePoint && _loc_4.equals(this._prePoint))
                {
                    
                }
                this._prePoint = _loc_4;
                AIManager.cancelAll();
                this._scene.moveRole(_loc_4);
            }
            
        }

        private function onConveyTo(event:DataEvent) : void
        {
            this._taskTargt = event.data as TaskTargetInfo;
            var _loc_2:* = SceneConfig.instance.getSceneInfo(this._taskTargt.mapId);
            if (Game.sceneInfo.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeBattlefield)
            {
                MsgManager.addBroadCast("在战场中，不能传送");
                
            }
            if (_loc_2 && _loc_2.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeBattlefield)
            {
                MsgManager.addBroadCast("不可向战场传送");
                
            }
            if (Game.sceneInfo.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeGuild)
            {
                MsgManager.addBroadCast("在仙盟领地中，不能传送");
                
            }
            if (_loc_2 && _loc_2.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeGuild)
            {
                this._taskTargt = cache.scene.getNearlyGuildNPC();
            }
            else
            {
                if (GameMapUtil.isEnemyMapByInfo(Game.sceneInfo))
                {
                    MsgManager.addBroadCast("在敌对阵营中，不能传送");
                    
                }
                if (GameMapUtil.isEnemyMap(this._taskTargt.mapId))
                {
                    MsgManager.addBroadCast("不可向敌对阵营传送");
                    
                }
            }
            if (Game.sceneInfo.sMapDefine.instanceType.__value == EMapInstanceType._EMapInstanceTypeCopy)
            {
                MsgManager.addBroadCast("副本中不能传送");
                
            }
            if (GameMapUtil.isCopyMap(this._taskTargt.mapId))
            {
                this._taskTargt = cache.scene.getNearlyCopyNPC(this._taskTargt.mapId);
            }
            if (cache.task.inTransport())
            {
                MsgManager.addBroadCast("护送中不能传送");
                
            }
            if (cache.guide.flyGuide)
            {
                AIManager.cancelAll();
                AIManager.onAIControl(this._taskTargt, AIType.AI_Convey);
                cache.guide.flyGuide = false;
            }
            else if (cache.vip.isVIP)
            {
                if (cache.vip.vipInfo._type == EVIPType._EVIPTypeWeek || cache.vip.vipInfo._type == EVIPType._EVIPTypeMonth)
                {
                    if (cache.pack.backPackCache.getTypeItems(ECategory._ECategoryProp, EProp._EPropPassToTarget).length == 0)
                    {
                        MsgManager.addBroadCast("背包中没有筋斗云，不能传送，黄金VIP可享受无限免费飞行。");
                        MsgManager.addTipText("背包中没有筋斗云，不能传送，黄金VIP可享受无限免费飞行。");
                    }
                    else
                    {
                        this.onConveyHandler(Alert.OK);
                    }
                }
                else
                {
                    this.onConveyHandler(Alert.OK);
                }
            }
            else
            {
                this.onConveyHandler(Alert.OK);
            }
            
        }

        private function onAlertHandler(param1:int) : void
        {
            if (param1 == Alert.OK && this._taskTargt != null)
            {
                AIManager.cancelAll();
                AIManager.onAIControl(this._taskTargt, AIType.AI_Convey);
            }
            
        }

        private function onConveyHandler(param1:int) : void
        {
            var _loc_2:SceneInfo = null;
            if (param1 == Alert.OK && this._taskTargt != null)
            {
                if (Cache.instance.role.entityInfo.level >= GameConst.SetFightModeLevel)
                {
                    if (RolePlayer.instance.entityInfo.entityInfo.fightModel == EEntityFightMode._EEntityFightModePeace)
                    {
                        if (GameMapUtil.isEnemyMap(this._taskTargt.mapId))
                        {
                            _loc_2 = SceneConfig.instance.getSceneInfo(this._taskTargt.mapId);
                            Alert.show("你将前往" + _loc_2.sMapDefine.name + "，进入后将被强制开启为战斗状态。", null, Alert.OK | Alert.CANCEL, null, this.onAlertHandler);
                        }
                        else
                        {
                            this.onAlertHandler(Alert.OK);
                        }
                    }
                    else
                    {
                        this.onAlertHandler(Alert.OK);
                    }
                }
                else if (GameMapUtil.isEnemyMap(this._taskTargt.mapId))
                {
                    Alert.show("等级不够" + GameConst.SetFightModeLevel + "级，不能进入敌对阵营");
                }
                else
                {
                    this.onAlertHandler(Alert.OK);
                }
            }
            
        }

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityInfos, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityMoveInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityLeftInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityLeftInfos, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityAttributeUpdate, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityAttributeUpdates, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityDropItem, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityFlashInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityOwner, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRoleMoveTo, this.roleMoveTo);
            NetDispatcher.addCmdListener(ServerCommand.RoleSingleAttributeChange, this.onRoleAttrChange);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityToEntityUpdate, this.onEntityToEntityUpdateHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityDoFight, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityBeginFight, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityBeginCollect, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityNpcShop, this.onNpcShopBroadCastHandler);
            Dispatcher.addEventListener(EventName.SysSettingSuccess, this.onSysSettingSuccessHandler);
            NetDispatcher.addCmdListener(ServerCommand.BufferUpdate, this.onBufferUpdate);
            NetDispatcher.addCmdListener(EventName.NPC_Task_StatusUpdata, this.onUpdateNPCStatus);
            Dispatcher.addEventListener(EventName.SkillUseSkill, this.onSkillFireHandler);
            Dispatcher.addEventListener(EventName.ItemUseItem, this.onItemUseHandler);
            Dispatcher.addEventListener(EventName.MountItemUseItem, this.onMountItemUseHandler);
            Dispatcher.addEventListener(ServerCommand.MapPointUpdate, this.onMapPointUpdate, false, 1000);
            Dispatcher.addEventListener(EventName.ConveyToReq, this.onConveyTo);
            Dispatcher.addEventListener(EventName.BeginToFight, this.onBeginToFight);
            Dispatcher.addEventListener(EventName.BeginToFightShortcut, this.onBeginToFightShortcut);
            Dispatcher.addEventListener(EventName.OverFight, this.onOverFight);
            Dispatcher.addEventListener(EventName.SetAutoFightSuccess, this.onSetAutoFight);
            Dispatcher.addEventListener(EventName.AutoFightGuideBegin, this.onAutoFightGuideBegin);
            
        }

        private function onRoleAttrChange(param1:Object) : void
        {
            RolePlayer.instance.showAttributChange(param1 as AttributeValue);
            
        }

        private function roleMoveTo(param1:MessageBlock) : void
        {
            var _loc_4:SPoint = null;
            var _loc_6:AStarPoint = null;
            var _loc_2:* = param1.messageBase as SPoints;
            var _loc_3:Array = [];
            var _loc_5:int = 0;
            while (_loc_5 < _loc_2.points.length)
            {
                
                _loc_4 = _loc_2.points[_loc_5];
                _loc_6 = new AStarPoint(_loc_4.x, _loc_4.y);
                _loc_3.push(_loc_6);
                _loc_5++;
            }
            RolePlayer.instance.walking(_loc_3);
            
        }

        private function onBeginToFight(event:DataEvent) : void
        {
            AutoFightRule.flag = AutoFightRule.AutoFightPanel;
            this.beginToFight();
            
        }

        private function onBeginToFightShortcut(event:DataEvent) : void
        {
            AutoFightRule.flag = AutoFightRule.AutoFightShoutcut;
            this.beginToFight();
            
        }

        private function onAutoFightGuideBegin(event:DataEvent) : void
        {
            AutoFightRule.flag = AutoFightRule.AutoFightHide;
            this.beginToFight();
            
        }

        private function beginToFight() : void
        {
            var _loc_1:Object = null;
            if (ThingUtil.entityUtil.isAutoFightAble(ThingUtil.selectEntity) && RolePlayer.instance.isCanAttackByPtP(ThingUtil.selectEntity))
            {
                if ((ThingUtil.selectEntity as MonsterPlayer).bossType == EBossType._EBossTypeCollection)
                {
                    AIManager.onAIControl(ThingUtil.selectEntity, AIType.AI_AutoFight);
                }
                else if (ThingUtil.selectEntity.entityInfo.isCanAttack())
                {
                    AIManager.onAIControl(ThingUtil.selectEntity, AIType.AI_AutoFight);
                }
            }
            else
            {
                _loc_1 = cache.scene.getAutoFightBoss(ThingUtil.entityUtil.getMonsterCodeList());
                AIManager.onAIControl(_loc_1, AIType.AI_AutoFight);
            }
            
        }

        private function onOverFight(event:DataEvent) : void
        {
            AIManager.stopCheckBossTimer();
            
        }

        private function onSetAutoFight(event:DataEvent) : void
        {
            var _loc_2:Object = null;
            AutoFightRule.flag = AutoFightRule.AutoFightPanel;
            if (this._scene)
            {
                if (AutoFightRule.isAutoFight())
                {
                    if (ThingUtil.entityUtil.isAutoFightAble(ThingUtil.selectEntity) && RolePlayer.instance.isCanAttackByPtP(ThingUtil.selectEntity))
                    {
                        if ((ThingUtil.selectEntity as MonsterPlayer).bossType == EBossType._EBossTypeCollection)
                        {
                            AIManager.onAIControl(ThingUtil.selectEntity, AIType.AI_AutoFight);
                        }
                        else if (ThingUtil.selectEntity.entityInfo.isCanAttack())
                        {
                            AIManager.onAIControl(ThingUtil.selectEntity, AIType.AI_AutoFight);
                        }
                    }
                    else
                    {
                        _loc_2 = cache.scene.getAutoFightBoss(ThingUtil.entityUtil.getMonsterCodeList());
                        AIManager.onAIControl(_loc_2, AIType.AI_AutoFight);
                    }
                }
            }
            
        }

        private function onMapPointUpdate(event:DataEvent) : void
        {
            var _loc_3:Point = null;
            RolePlayer.instance.entityInfo.setNotFighting();
            var _loc_2:* = event.data as SPassTo;
            if (_loc_2.mapId != MapFileUtil.mapID)
            {
                if (ThingUtil.selectEntity != null)
                {
                    ThingUtil.selectEntity.selected = false;
                }
                this._scene.clearAll();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChangeScene));
                this._scene.setPlayerPoint(_loc_2.mapId, _loc_2.toPoint.x, _loc_2.toPoint.y);
            }
            else
            {
                _loc_3 = GameMapUtil.getPixelPoint(_loc_2.toPoint.x, _loc_2.toPoint.y);
                if (SceneRange.display.contains(_loc_3.x, _loc_3.y) == false)
                {
                    if (ThingUtil.selectEntity)
                    {
                        ThingUtil.selectEntity.selected = false;
                    }
                    this._scene.mapLayer.clearMap(true);
                }
                RolePlayer.instance.setTitlePoint(_loc_2.toPoint.x, _loc_2.toPoint.y);
                RolePlayer.instance.stopMove();
                ThingUtil.isEntitySort = true;
                ThingUtil.isMoveChange = true;
                this._scene.playerLayer.sortEntitys();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChangePosition, RolePlayer.instance.currentPoint));
            }
            this._scene.removePointMark();
            
        }

        private function onSysSettingSuccessHandler(event:DataEvent) : void
        {
            ThingUtil.entityUtil.updateLifeShow();
            ThingUtil.entityUtil.updateUserNameShow();
            ThingUtil.entityUtil.updateNearPlayerPetShow();
            
        }

        private function onBufferUpdate(param1:Object) : void
        {
            RolePlayer.instance.updateState(cache.buff.tStateArray);
            var _loc_2:int = 0;
            while (_loc_2 < cache.buff.sBufferMsg.buffers.length)
            {
                
                RolePlayer.instance.updateBuffer((cache.buff.sBufferMsg.buffers[_loc_2] as SBuffer).code, cache.buff.updateType);
                _loc_2++;
            }
            
        }

        private function onUpdateNPCStatus(param1:Array) : void
        {
            var _loc_2:int = 0;
            var _loc_4:NPCInfo = null;
            var _loc_5:NPCPlayer = null;
            if (param1 == null)
            {
                
            }
            var _loc_3:* = param1.length;
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = param1[_loc_2];
                _loc_5 = ThingUtil.npcUtil.getNpc(_loc_4.tnpc.npcId);
                if (_loc_5 != null)
                {
                    _loc_5.updateStatus(_loc_4);
                }
                _loc_2++;
            }
            
        }

        private function onSkillFireHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as TSkill;
            SkillsUtil.instance.fireSkill(_loc_2, ThingUtil.selectEntity);
            
        }

        private function onItemUseHandler(event:DataEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, event.data as ItemData));
            
        }

        private function onMountItemUseHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            MountUtil.instance.equipMount(_loc_2);
            
        }

        private function onEntityInfoUpdateHandler(event:PlayerEvent) : void
        {
            NetDispatcher.dispatchCmd(ServerCommand.EntityInfo_Update, null);
            
        }

        private function onEntityToEntityUpdateHandler(param1:MessageBlock) : void
        {
            var _loc_2:* = param1.messageBase as SEntityIdPair;
            var _loc_3:* = ThingUtil.entityUtil.getEntity(_loc_2.fromEntityId) as UserPlayer;
            var _loc_4:* = ThingUtil.entityUtil.getEntity(_loc_2.toEntityId) as UserPlayer;
            if (_loc_3 && _loc_4)
            {
                _loc_3.entityInfo.entityInfo.toEntitys = [_loc_2.toEntityId];
                if (_loc_3.isDoubleRest)
                {
                    _loc_3.doubleRest();
                }
            }
            
        }

        private function onNpcShopBroadCastHandler(param1:MessageBlock) : void
        {
            this.entityNpcShop(param1.messageBase as SNpcShop);
            
        }

        private function onBroadCastHandler(param1:MessageBlock) : void
        {
            var _loc_2:SEntityMoveInfo = null;
            var _loc_3:SSeqEntityIdInfo = null;
            var _loc_4:SEntityIdPair = null;
            var _loc_5:SEntityMoveInfo = null;
            switch(param1.messageHead.command)
            {
                case ECmdBroadCast._ECmdBroadcastEntityInfo:
                {
                    this.addEntity(param1.messageBase as SEntityInfo);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityInfos:
                {
                    this.addEntitys((param1.messageBase as SSeqEntityInfo).entityInfos);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityMoveInfo:
                {
                    _loc_2 = param1.messageBase as SEntityMoveInfo;
                    this.moveEntity(_loc_2.entityId, _loc_2.points);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityDropItem:
                {
                    this.dropItem(param1.messageBase as SPacket);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityLeftInfo:
                {
                    this.removeEntity(param1.messageBase as SEntityId);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityLeftInfos:
                {
                    _loc_3 = param1.messageBase as SSeqEntityIdInfo;
                    ThingUtil.entityUtil.removeEntitys(_loc_3.entityIds);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityAttributeUpdate:
                {
                    this.updateAttributes(param1.messageBase as SEntityUpdate);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityBeginFight:
                {
                    if (this._scene)
                    {
                        ThingUtil.fightUtil.beginFight(param1.messageBase as SBeginFight);
                    }
                    break;
                }
                case EGateCommand._ECmdGateShortcut:
                {
                    if (this._scene)
                    {
                        ThingUtil.shortCutUtil.beginUse(param1.messageBase as SShortcut);
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityDoFight:
                {
                    if (this._scene)
                    {
                        ThingUtil.fightUtil.doFight(param1.messageBase as SDoFight);
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityOwner:
                {
                    _loc_4 = param1.messageBase as SEntityIdPair;
                    ThingUtil.entityUtil.updateAttack(_loc_4);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityBeginCollect:
                {
                    if (this._scene)
                    {
                        ThingUtil.collectUtil.beginFight(param1.messageBase as SBeginFight);
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityFlashInfo:
                {
                    _loc_5 = param1.messageBase as SEntityMoveInfo;
                    ThingUtil.entityUtil.refreshPoint(_loc_5.entityId, _loc_5.points);
                    break;
                }
                default:
                {
                    break;
                }
            }
            
        }

        public function addEntitys(param1:Array) : void
        {
            if (this._scene && this._scene.isInitialize)
            {
                ThingUtil.entityUtil.addEntitys(param1);
            }
            else
            {
                this._entritysAry = this._entritysAry.concat(param1);
            }
            
        }

        public function addEntity(param1:SEntityInfo) : void
        {
            if (this._scene && this._scene.isInitialize)
            {
                ThingUtil.entityUtil.addEntity(param1);
            }
            else
            {
                this._entritysAry.push(param1);
            }
            
        }

        public function removeEntitys(param1:Array) : void
        {
            if (this._scene)
            {
                ThingUtil.entityUtil.removeEntitys(param1);
            }
            
        }

        public function removeEntity(param1:SEntityId) : void
        {
            if (this._scene)
            {
                ThingUtil.entityUtil.removeEntity(param1);
            }
            
        }

        public function moveEntity(param1:SEntityId, param2:Array) : void
        {
            var _loc_3:Array = null;
            var _loc_4:SPoint = null;
            var _loc_5:int = 0;
            var _loc_6:AStarPoint = null;
            if (this._scene)
            {
                _loc_3 = [];
                _loc_5 = 0;
                while (_loc_5 < param2.length)
                {
                    
                    _loc_4 = param2[_loc_5];
                    _loc_6 = new AStarPoint(_loc_4.x, _loc_4.y);
                    _loc_3.push(_loc_6);
                    _loc_5++;
                }
                ThingUtil.entityUtil.moveEntity(param1, _loc_3);
            }
            
        }

        private function updateAttributes(param1:SEntityUpdate) : void
        {
            var _loc_2:SEntityInfo = null;
            if (this._scene && this._scene.isInitialize)
            {
                ThingUtil.userUtil.updateAttribute(param1);
            }
            else
            {
                for each (_loc_2 in this._entritysAry)
                {
                    
                    if (EntityUtil.toString(_loc_2.entityId) == EntityUtil.toString(param1.entityId))
                    {
                        EntityUtil.updateEntityAttribute(_loc_2, param1.propertyUpdates);
                        
                    }
                }
            }
            
        }

        public function dropItem(param1:SPacket) : void
        {
            if (this._scene && this._scene.isInitialize)
            {
                ThingUtil.dropItemUtil.addDropItem(param1);
            }
            else
            {
                this._dropItemAry.push(param1);
            }
            
        }

        public function entityNpcShop(param1:SNpcShop) : void
        {
            if (this._scene && this._scene.isInitialize)
            {
                ThingUtil.npcShopUtil.addNpcShop(param1);
            }
            else
            {
                this._npcShopAry.push(param1);
            }
            
        }

        public function get selectEntity() : IEntity
        {
            return ThingUtil.selectEntity;
        }

    }
}
